package org.dromara.system.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.system.domain.vo.TDaAlarmDataTempVo;
import org.dromara.system.domain.bo.TDaAlarmDataTempBo;
import org.dromara.system.service.ITDaAlarmDataTempService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 报警信息表
 *
 * @author Liu
 * @date 2023-11-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/daAlarmDataTemp")
public class TDaAlarmDataTempController extends BaseController {

    private final ITDaAlarmDataTempService tDaAlarmDataTempService;

    /**
     * 查询报警信息表列表
     */
    @SaCheckPermission("system:daAlarmDataTemp:list")
    @GetMapping("/list")
    public TableDataInfo<TDaAlarmDataTempVo> list(TDaAlarmDataTempBo bo, PageQuery pageQuery) {
        return tDaAlarmDataTempService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出报警信息表列表
     */
    @SaCheckPermission("system:daAlarmDataTemp:export")
    @Log(title = "报警信息表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TDaAlarmDataTempBo bo, HttpServletResponse response) {
        List<TDaAlarmDataTempVo> list = tDaAlarmDataTempService.queryList(bo);
        ExcelUtil.exportExcel(list, "报警信息表", TDaAlarmDataTempVo.class, response);
    }

    /**
     * 获取报警信息表详细信息
     *
     * @param ID 主键
     */
    @SaCheckPermission("system:daAlarmDataTemp:query")
    @GetMapping("/{ID}")
    public R<TDaAlarmDataTempVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long ID) {
        return R.ok(tDaAlarmDataTempService.queryById(ID));
    }

    /**
     * 新增报警信息表
     */
    @SaCheckPermission("system:daAlarmDataTemp:add")
    @Log(title = "报警信息表", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TDaAlarmDataTempBo bo) {
        return toAjax(tDaAlarmDataTempService.insertByBo(bo));
    }

    /**
     * 修改报警信息表
     */
    @SaCheckPermission("system:daAlarmDataTemp:edit")
    @Log(title = "报警信息表", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TDaAlarmDataTempBo bo) {
        return toAjax(tDaAlarmDataTempService.updateByBo(bo));
    }

    /**
     * 删除报警信息表
     *
     * @param IDs 主键串
     */
    @SaCheckPermission("system:daAlarmDataTemp:remove")
    @Log(title = "报警信息表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] IDs) {
        return toAjax(tDaAlarmDataTempService.deleteWithValidByIds(List.of(IDs), true));
    }
}
